<template>
	<view class="container mySetupclass">
		<view class="inputBox" v-if="type==='1'">
			<input class="setupInput" type="text" v-model="userName" placeholder="请输入您的姓名" @focus="focusFlg=true" @blur="focusFlg=false" :class="focusFlg?'active':''"/>
			<view class="remarks">
				注:填写户籍登记所用的姓名
			</view>
			<view class="updataButton" :class="userName?'yesClick':''" @tap="preserve">
				确定
			</view>
		</view>
		<view class="inputBox" v-if="type==='0'">
			<input class="setupInput" maxlength="11" type="text" v-model="userMobile" placeholder="请输入您的手机号" @focus="focusFlg=true" @blur="focusFlg=false" :class="focusFlg?'active':''"/>
			<view class="remarks">
				注:填写正确的手机号
			</view>
			<view @tap="preserve" class="updataButton" :class="userMobile?'yesClick':''">
				确定
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type:'1',
				userName:'', //姓名
				userMobile:'', //电话
				height:0,
				focusFlg:false
			}
		},
		onLoad(options) {
			// #ifdef H5
			   this.$wechat.noShare();
			// #endif
			// this.getDictDataAll()
			// this.height = wx.getSystemInfoSync().windowHeight;
			// console.log(this.skinArrayAll)
			// this.skinArrayAll.skin_Type.forEach((item)=>{
			// 	this.skinArray.push(item.dictLabel)
			// })
			if(options){
				this.type=options.type
				console.log(options.data)
				if(options.type==='1'){
					if(options.data&&options.data!=='null'){
						this.userName=options.data
					}else{
						this.userName=''
					}
					
				}else{
					if(options.data&&options.data!=='null'){
						this.userMobile=options.data
					}else{
						this.userMobile=''
					}
					
				}
			}
		},
		methods: {
			preserve(){
				console.log(this.type)
				let params={}
				if(this.type==='1'){
					if(!this.userName){
						uni.showToast({
							title: '请输入您的姓名',
							icon:'none',
						})
						return
					}else{
						params.userName=this.userName
						params.type=2
						this.$http.customersUpdate(params).then((res) => {
							if(res.status === 0) {
								uni.showToast({
									title: '保存成功',
									icon:'none',
								})
								setTimeout(()=>{
									setTimeout(()=>{
										uni.navigateBack();
									}, 500)
								}, 500)
							}
						})
					}
				}else{
					if(!this.userMobile){
						uni.showToast({
							title: '请输入您的手机号',
							icon:'none',
						})
						return
					}else if(!this.$util.checkStr(this.userMobile, 'mobile')){
						uni.showToast({
							title: '请输入正确的手机号',
							icon:'none',
						})
						return
					}else{
						params.userMobile=this.userMobile
						params.type=3
						this.$http.customersUpdate(params).then((res) => {
							if(res.status === 0) {
								uni.showToast({
									title: '保存成功',
									icon:'none',
								})
								setTimeout(()=>{
									uni.navigateBack();
								}, 500)
							}
						})
					}
				}
				console.log(params)
			}
		}
	}
</script>

<style lang="scss">
	.mySetupclass{
		background-color: #fff;
		height: 100vh;
		font-size: 30rpx;
	}
	.inputBox{
		padding: 20rpx 30rpx;
	}
	.remarks{
		color: #999;
		font-size: 24rpx;
		margin: 28rpx 0rpx 62rpx 20rpx;
	}
	.setupInput , .updataButton{
		border: 1px solid #ddd;
		border-radius: 40rpx;
		padding: 10rpx 32rpx;
		height: 80rpx;
	}
	.updataButton{
		display: flex;
		justify-content: center;
		height: 100rpx;
		align-items: center;
		background: #DDDDDD;
		font-size: 19px;
		font-weight: 500;
		color: #FFFFFF;
	}
	.active{
		border: 1px solid rgba(237, 117, 111, 1);
		border-radius: 40rpx;
	}
	.yesClick{
		border: none;
		background: linear-gradient(151deg, #F69E97 0%, #EA655E 100%);
		border-radius: 50rpx;
	}
</style>
